<?php
require_once 'database_wcc.php';
setlocale(LC_ALL, 'zh_CN.utf-8');

class materialClass extends database_wcc {
	private $test_datasource = 'test_datasource';
	function __construct ($config=NULL){
		parent::__construct($this->test_datasource);
	}
	function getCount(){
		$sql = "select count(*) as number from material";
    	return $this->getTotalNumber($sql);
	}


	function getCount2($cate){
		$sql = "select count(*) as number from material where cate='$cate' ";
		// echo $sql;
		// echo '<br>';
    	return $this->getTotalNumber($sql);
	}


	function getAll(){
		$sql = "select * from material order by update_time desc";
		return $this->selectArray($sql);
	}	

	function getAll2($cate){
		$sql = "select * from material where cate='$cate' order by update_time desc";
		// echo $sql;
		// echo '<br>';
		return $this->selectArray($sql);
	}	
	function getAll3($cate){
		$sql = "select * from material where cate='$cate' and top=1 order by update_time desc";
		// echo $sql;
		// echo '<br>';
		return $this->selectArray($sql);
	}	


	function add($media_id,$title,$thumb_media_id,$show_cover_pic,$author,$digest,$content,$url,$content_source_url,$update_time){		
		$sql = "INSERT  INTO material(media_id,title,thumb_media_id,show_cover_pic,author,digest,content,url,content_source_url,update_time) Values('$media_id','$title','$thumb_media_id','$show_cover_pic','$author','$digest','$content','$url','$content_source_url','$update_time')";
    	echo $sql;
    	echo '<br>';
    	$this->update_sql($sql);
	}	


	// CREATE TABLE `material` (
	//   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
	//   `cate` varchar(255) DEFAULT NULL,
	//   `media_id` varchar(255) DEFAULT NULL,
	//   `title` varchar(255) DEFAULT NULL,
	//   `thumb_media_id` varchar(255) DEFAULT NULL,
	//   `show_cover_pic` varchar(255) DEFAULT NULL,
	//   `author` varchar(255) DEFAULT NULL,
	//   `digest` varchar(255) DEFAULT NULL,
	//   `content` varchar(255) DEFAULT NULL,
	//   `url` varchar(255) DEFAULT NULL,
	//   `content_source_url` varchar(255) DEFAULT NULL,
	//   `update_time` int(11) DEFAULT NULL,
	//   PRIMARY KEY (`id`)
	// ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

	function update($id,$cate){
		$sql = "update material set cate='$cate' where id=$id ";
    	echo $sql;
    	echo '<br>';
    	$this->update_sql($sql);
	}


	function update2($id){
		$sql = "update material set top='1' where id=$id ";
    	echo $sql;
    	echo '<br>';
    	$this->update_sql($sql);
	}

	function update3($id){
		$sql = "update material set top='0' where id=$id ";
    	echo $sql;
    	echo '<br>';
    	$this->update_sql($sql);
	}	

	function del($id){
		$sql = "delete from material where id='$id'";
    	//echo $sql;
    	//echo '<br>';
    	$this->update_sql($sql);
	}		
	function drop($website){
		$sql = "delete from material where website='$website'";
    	echo $sql;
    	echo '<br>';
    	$this->update_sql($sql);
	}	
}